<#include "/common/_layout.html"/>
<@layout>
	<style>

	</style>
	<div id="app">
		<el-form ref="form" :rules="rules" :model="form" label-width="100px" v-loading="loading">
			<el-form-item label="商品规格" prop="goods_spec">
				<el-input v-model.trim="form.goods_spec" disabled></el-input>
			</el-form-item>

			<el-tabs type="card">
				<el-tab-pane label="入库情况">

					<el-row :gutter="20" style="margin-left: 0;margin-right: 0;">
						<el-col :span="12">
							<template v-for="(item, index) in store">
								<template v-if="index % 2 == 0">
									<el-form-item :label="item.name" :prop="'store_' + item.id">
										<el-input-number v-model="form_store[item.id]" :precision="0" :step="1" :min="0"></el-input-number>
										<span style="margin-left: 5px;">个</span>
									</el-form-item>
								</template>
							</template>
						</el-col>

						<el-col :span="12">
							<template v-for="(item, index) in store">
								<template v-if="index % 2 == 1">
									<el-form-item :label="item.name" :prop="'store_' + item.id">
										<el-input-number v-model="form_store[item.id]" :precision="0" :step="1" :min="0"></el-input-number>
										<span style="margin-left: 5px;">个</span>
									</el-form-item>
								</template>
							</template>
						</el-col>

					</el-row>

				</el-tab-pane>
			</el-tabs>

		</el-form>

		<el-row class="lb_form_button">
			<el-button type="primary" @click="submitForm('form')">提交</el-button>
			<el-button type="danger" @click="closeDlalog">关闭</el-button>
		</el-row>
	</div>

	<script type="text/javascript">
		var _vue = new Vue({
			el: '#app',
			data: function() {
				return {
					store: eval('${store}'),
					form_store: {},
					form: {
						goods_spec: ""
					},
					rules: {},
					loading: false
				}
			},
			methods: {
				submitForm: function(formName) {
					var params = {};
					params["goods.id"] = parent.selectData.id;
					params["goodsStore"] = JSON.stringify(this.form_store);
					FormUtils.submit(this, formName, "${ctx}/goods/update", params);
				},
				closeDlalog: function() {
					//关闭当前这个iframe的dialog
					parent._vue[window.frameElement.id].dialogVisible = false;
				}
			},
			mounted: function() {
				if(!!parent.selectData) {
					var selectData = parent.selectData;
					var _that = this;
					// 通用遍历form赋初始值的方法
					$.each(selectData, function(key, value) {
						if(_that.form[key] != undefined) {
							_that.form[key] = value;
						}
					});
					// 初始化仓库值
					$.each(selectData.goodsStores, function(key, value) {
						_that.form_store[value.store_id] = value.num;
					});
				} else {
					parent._vue.$message({
						message: "发生错误,无法编辑",
						type: 'error'
					});
					this.closeDlalog();
				}
			}
		});
	</script>
</@layout>